using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class InteractionFeedBacks : MonoBehaviour
{
    public AudioClip OnHitSound;
    public AudioClip OnDeathSound;
    public ParticleSystem OnHitParticles;

    public void PlayHitReaction()
    {
        PlayHitSound();
        ShakeGameObject(0.2f);
        StretchGameObject();
        PlayHitParticles();
    }

    public void PlayDeathReaction()
    {
        PlayDeathSound();
    }
    
    public void PlayHitSound()
    {
        AudioSource.PlayClipAtPoint(OnHitSound, transform.position);
    }

    public void PlayDeathSound()
    {
        AudioSource.PlayClipAtPoint(OnDeathSound, transform.position);
    }

    public void ShakeGameObject(float strength)
    {
        var seq = DOTween.Sequence();
        var shake = transform.DOShakePosition(0.2f, strength);
        seq.Join(shake);
    }

    public void PlayHitParticles()
    {
        var particle = Instantiate(OnHitParticles, transform.position, Quaternion.identity);
        particle.Play();
    }
    
    public void StretchGameObject()
    {
        var seqStart = DOTween.Sequence();
        var seqEnd = DOTween.Sequence();
        var stretchStartX = transform.DOScaleX(1.2f, 0.1f);
        var stretchStartY = transform.DOScaleY(0.8f, 0.1f);
        var stretchEndX = transform.DOScaleX(0.8f, 0.1f);
        var stretchEndY = transform.DOScaleY(1.2f, 0.1f);
        var stretchEnd = transform.DOScale(Vector3.one, 0.1f);
        seqStart.Join(stretchStartX).Join(stretchStartY);
        seqEnd.Join(stretchEndX).Join(stretchEndY);
        seqStart.Append(seqEnd).Append(stretchEnd);
    }
}
